# Maintainer: Alexey Pavlov <alexpux@gmail.com>
# Contributor: Ray Donnelly <mingw.android@gmail.com>

_pyname=Sphinx
_realname=sphinx
pkgbase=mingw-w64-python3-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
pkgver=2.2.0
pkgrel=1
pkgdesc="Python documentation generator (mingw-w64)"
arch=('any')
license=('BSD')
url="https://www.sphinx-doc.org/"
depends=("${MINGW_PACKAGE_PREFIX}-python3-babel"
         "${MINGW_PACKAGE_PREFIX}-python3-colorama"
         "${MINGW_PACKAGE_PREFIX}-python3-docutils"
         "${MINGW_PACKAGE_PREFIX}-python3-imagesize"
         "${MINGW_PACKAGE_PREFIX}-python3-jinja"
         "${MINGW_PACKAGE_PREFIX}-python3-pygments"
         "${MINGW_PACKAGE_PREFIX}-python3-requests"
         "${MINGW_PACKAGE_PREFIX}-python3-setuptools"
         "${MINGW_PACKAGE_PREFIX}-python3-snowballstemmer"
         "${MINGW_PACKAGE_PREFIX}-python3-sphinx-alabaster-theme"
         "${MINGW_PACKAGE_PREFIX}-python3-sphinxcontrib-applehelp"
         "${MINGW_PACKAGE_PREFIX}-python3-sphinxcontrib-devhelp"
         "${MINGW_PACKAGE_PREFIX}-python3-sphinxcontrib-htmlhelp"
         "${MINGW_PACKAGE_PREFIX}-python3-sphinxcontrib-jsmath"
         "${MINGW_PACKAGE_PREFIX}-python3-sphinxcontrib-serializinghtml"
         "${MINGW_PACKAGE_PREFIX}-python3-sphinxcontrib-qthelp")
optdepends=("${MINGW_PACKAGE_PREFIX}-imagemagick: ext.imageconverter")
checkdepends=("${MINGW_PACKAGE_PREFIX}-python3-pytest")
source=("${_realname}-${pkgver}.tar.gz"::"https://pypi.org/packages/source/S/${_pyname}/${_pyname}-${pkgver}.tar.gz")
sha256sums=('0d586b0f8c2fc3cc6559c5e8fd6124628110514fda0e5d7c82e682d749d2e845')

build() {
  cd "${srcdir}/${_realname}-${pkgver}"
  ${MINGW_PREFIX}/bin/python3 setup.py build
}

check() {
  cd "${srcdir}/${_realname}-${pkgver}"
  #2 failed, 1165 passed, 21 skipped, 3 xfailed, 30 xpassed, 3 warnings
  ${MINGW_PREFIX}/bin/py.test || warning "test failed"
}

package_python3-sphinx() {
  cd "${srcdir}/${_realname}-${pkgver}"
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python3 setup.py install --prefix=${MINGW_PREFIX} --root="${pkgdir}" -O1

  local PREFIX_WIN=$(cygpath -wm ${MINGW_PREFIX})
  # fix python command in files
  for _f in "${pkgdir}${MINGW_PREFIX}"/bin/*.py; do
    sed -e "s|/usr/bin/env |${MINGW_PREFIX}|g" \
        -e "s|${PREFIX_WIN}|${MINGW_PREFIX}|g" -i ${_f}
  done

  install -Dm644 LICENSE "${pkgdir}${MINGW_PREFIX}"/share/licenses/python3-sphinx/LICENSE
}

package_mingw-w64-i686-python3-sphinx() {
  install=${_realname}3-${CARCH}.install
  package_python3-sphinx
}

package_mingw-w64-x86_64-python3-sphinx() {
  install=${_realname}3-${CARCH}.install
  package_python3-sphinx
}
